//=============================================================================
// CoolStorage.NET - .NET Object Relational Mapping Library 
//
// Copyright (c) 2004-2007 Philippe Leybaert
//
// Permission is hereby granted, free of charge, to any person obtaining a copy 
// of this software and associated documentation files (the "Software"), to deal 
// in the Software without restriction, including without limitation the rights 
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
// copies of the Software, and to permit persons to whom the Software is 
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in 
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//=============================================================================

using System;

namespace Activa.CoolStorage
{
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property)]
	public sealed class MapToAttribute : Attribute
	{
		private readonly string _name;
		private readonly string _context;

		public MapToAttribute(string name)
		{
			_name = name;
		}

		public MapToAttribute(string name , string context)
			: this(name)
		{
			_context = context;
		}

		public string Name
		{
			get { return _name; }
		}

		public string Context
		{
			get { return _context; }
		}
	}

	[AttributeUsage(AttributeTargets.Class)]
	public sealed class DefaultSortExpressionAttribute : Attribute
	{
		private readonly string _expression;

		public DefaultSortExpressionAttribute(string sortExpression)
		{
			_expression = sortExpression;
		}

		public string Expression
		{
			get { return _expression; }
		}
	}

	[AttributeUsage(AttributeTargets.Property)]
	public sealed class DefaultSortAttribute : Attribute
	{
		private readonly CSSort _sortDirection = CSSort.Ascending;

		public DefaultSortAttribute()
		{
		}

		public DefaultSortAttribute(CSSort sortDirection)
		{
			_sortDirection = sortDirection;
		}


		public CSSort SortDirection
		{
			get { return _sortDirection; }
		}
	}
	
    [AttributeUsage(AttributeTargets.Property)]
    public sealed class TrimAttribute : Attribute
    {
    }

	[AttributeUsage(AttributeTargets.Property)]
	public sealed class LazyAttribute : Attribute
	{
	}

	[AttributeUsage(AttributeTargets.Property)]
	public sealed class NoCreateAttribute : Attribute
	{
	}

	[AttributeUsage(AttributeTargets.Property)]
	public sealed class ToStringAttribute : Attribute
	{
	}

    [AttributeUsage(AttributeTargets.Property)]
    public sealed class BooleanValueAttribute : Attribute
    {
        private readonly object _trueValue;
        private readonly object _falseValue;

        public BooleanValueAttribute(string trueValue, string falseValue)
        {
			_trueValue = trueValue;
			_falseValue = falseValue;
        }

        public BooleanValueAttribute(string trueValue)
        {
			_trueValue = trueValue;
        }

        public BooleanValueAttribute(int trueValue, int falseValue)
        {
			_trueValue = trueValue;
			_falseValue = falseValue;
        }

        public BooleanValueAttribute(int trueValue)
        {
			_trueValue = trueValue;
        }

    	public object TrueValue
    	{
    		get { return _trueValue; }
    	}

    	public object FalseValue
    	{
    		get { return _falseValue; }
    	}
    }

	[AttributeUsage(AttributeTargets.Property)]
	public sealed class NullValueAttribute : Attribute
	{
		private readonly object _nullValue;

		public NullValueAttribute(Int32 i)
		{
			_nullValue = i;
		}

		public NullValueAttribute(Double d)
		{
			_nullValue = d;
		}

		public NullValueAttribute(Boolean b)
		{
			_nullValue = b;
		}

		public NullValueAttribute(DateTime dt)
		{
			_nullValue = dt;
		}

		public NullValueAttribute(string s)
		{
			_nullValue = s;
		}

		public object NullValue
		{
			get { return _nullValue; }
		}
	}

	[AttributeUsage(AttributeTargets.Property)]
	public abstract class RelationAttribute : Attribute
	{
		private string _localKey;
		private string _foreignKey;

		public string LocalKey
		{
			get { return _localKey; }
			set { _localKey = value; }
		}

		public string ForeignKey
		{
			get { return _foreignKey; }
			set { _foreignKey = value; }
		}
	}

	[AttributeUsage(AttributeTargets.Property)]
	public sealed class OneToManyAttribute : RelationAttribute
	{
	}

	[AttributeUsage(AttributeTargets.Property)]
	public sealed class OneToOneAttribute : RelationAttribute
	{
	}

	[AttributeUsage(AttributeTargets.Property)]
	public sealed class ManyToOneAttribute : RelationAttribute
	{
	}

    [AttributeUsage(AttributeTargets.Property)]
    public sealed  class SequenceAttribute : Attribute
    {
        private string _sequenceName;

        public SequenceAttribute(string sequenceName)
        {
            _sequenceName = sequenceName;
        }

        public string SequenceName
        {
            get { return _sequenceName; }
        }
    }

	[AttributeUsage(AttributeTargets.Property)]
	public sealed class ManyToManyAttribute : RelationAttribute
	{
		private string _localLinkKey;
		private string _foreignLinkKey ;
		private string _linkTable;
		private bool   _pure;

		public ManyToManyAttribute(string linkTable)
		{
			_linkTable = linkTable;
		}

		public bool Pure
		{
			get { return _pure; }
			set { _pure = value; }
		}

		public string LocalLinkKey
		{
			get { return _localLinkKey; }
			set	{ _localLinkKey = value; }
		}

		public string ForeignLinkKey
		{
			get { return _foreignLinkKey; }
			set { _foreignLinkKey = value; }
		}

		public string LinkTable
		{
			get { return _linkTable; }
			set { _linkTable = value; }
		}
	}

    [AttributeUsage(AttributeTargets.Property)]
    public sealed class OptimisticLockAttribute : Attribute
    {
    }

	[AttributeUsage(AttributeTargets.Class)]
	public sealed class QueryExpressionAttribute : Attribute
	{
		private readonly string _query;

		public QueryExpressionAttribute(string sqlQuery)
		{
			_query = sqlQuery;
		}

		public string Query
		{
			get { return _query; }
		}
	}

	[AttributeUsage(AttributeTargets.Property)]
	public sealed class PrefetchAttribute : Attribute
	{
	}

    [AttributeUsage(AttributeTargets.Property)]
    public sealed class ServerGeneratedAttribute : Attribute
    {
    }

    [AttributeUsage(AttributeTargets.Property)]
    public sealed class ClientGeneratedAttribute : Attribute
    {
    }

    [AttributeUsage(AttributeTargets.Property)]
    public sealed class NotMappedAttribute : Attribute
    {
    }

}
